home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / mflms101.arc / OKISET.C < prev    next >
C/C++ Source or Header  |  1989-11-25  |  15KB  |  546 lines

  1. /*
  2. **                OKIDATA PRINTER SETUP UTILITY
  3. ** Copyright 1987, S.E. Margison
  4. ** 1-11-87 A
  5. **
  6. **   As distributed, this program requires (for compilation):
  7. **     "The MicroFirm Function LIbrary for MS/QC"
  8. **   which may be obtained without registration from many Bulletin
  9. **   Board Systems.
  10. **
  11. **   or by registration:
  12. **      $25 for Docs, C, S, M, L, H libraries, and complete library source
  13. **              in C and Assembler
  14. **     MicroFirm
  15. **     P.O. Box 428
  16. **     Alief, TX 77411
  17. **
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <ctype.h>
  23. #include <mflsys.h>
  24. #include <mflconio.h>
  25. #include <mflfiles.h>
  26.  
  27. #undef NONE
  28. #define NONE 0xff
  29. #define PICA 0
  30. #define COND 1
  31. #define DRAFT 0
  32. #define LQ 1
  33. #define beep putchar(BEL)
  34.  
  35. short length, linespc, lqspc, pitch, style;
  36. short printer;  /* 0 = PRN, 1 = LPT1, 2 = LPT2 */
  37.  
  38. char pica[] =  "NORMAL   ",
  39.      cond[] =  "CONDENSED",
  40.      draft[] = "DRAFT         ",
  41.      lq[] =    "LETTER QUALITY",
  42.      lpt1[] = "LPT1:",
  43.      lpt2[] = "LPT2:",
  44.      prn[] = "PRN: ";
  45.  
  46. char line1[] = "OKIDATA ML84 CONFIGURATOR V1.10",
  47.      line2[] = "- by Steven E. Margison -",
  48.      line3[] = "Copyright 1986 -- All Rights Reserved",
  49.      line4[] = "F1   Pitch: ",
  50.      line5[] = "F2   Style: ",
  51.      line6[] = "F3   LQ spacing: ",
  52.      line7[] = "F4   Form Length (lines): ",
  53.      line8[] = "F5   Line Spacing: ",
  54.      line9[] = "F6   ",
  55.      line10[]= "F7   Output Channel - ",
  56.      line11[]= "F8   Normal Defaults",
  57.      line12[]= "F9   Send Control Codes",
  58.      line13[]= "FK10  -- Return to DOS --",
  59.      line14[]= "Waiting...",
  60.      cline[]="                                                        ";
  61.  
  62. main()
  63. {           /* no command line arguments */
  64.         int key;
  65.  
  66.         printer = 0;
  67.         lqspc = linespc = pitch = style = length = NONE;
  68.         domenu(FALSE);           /* initialize the screen */
  69.  
  70.         while(TRUE)
  71.         {
  72.                 key = getkey();    /* get a function code */
  73.                 if(key < 0xff)
  74.                 {
  75.                         beep;
  76.                         continue;
  77.                 }
  78.                 key &= 0x7f;
  79.                 switch(key)
  80.                 {
  81.                 case FK1:   /* select pitch */
  82.                         dofk1();
  83.                         if((pitch == COND) && (style == LQ))
  84.                         {
  85.                                 style = DRAFT;
  86.                                 putstyle();
  87.                         }
  88.                         prompt();
  89.                         break;
  90.                 case FK2:   /* select style */
  91.                         dofk2();
  92.                         if((style == LQ) && (pitch == COND))
  93.                         {
  94.                                 pitch = PICA;
  95.                                 putpitch();
  96.                         }
  97.                         prompt();
  98.                         break;
  99.                 case FK3:   /* specify LQ character spacing */
  100.                         if((lqspc = get2digs(9, 32)) == NONE)
  101.                         {
  102.                                 prompt();
  103.                                 break;
  104.                         }
  105.                         if(style != LQ)
  106.                         {
  107.                                 style = LQ;
  108.                                 putstyle();
  109.                                 if(pitch == COND)
  110.                                 {
  111.                                         pitch = PICA;
  112.                                         putpitch();
  113.                                 }
  114.                         }
  115.                         if(lqspc > 0x11)
  116.                         {
  117.                                 lqspc = 0;
  118.                                 warn(1);
  119.                                 putlqspc();
  120.                         }
  121.                         prompt();
  122.                         break;
  123.                 case FK4:   /* specify Form length in lines */
  124.                         if((length = get2digs(10, 41)) == NONE)
  125.                         {
  126.                                 prompt();
  127.                                 break;
  128.                         }
  129.                         if(length == 0)
  130.                         {
  131.                                 length = 0x66;
  132.                                 warn(2);
  133.                                 putlength();
  134.                         }
  135.                         prompt();
  136.                         break;
  137.                 case FK5:  /* specify line spacing */
  138.                         dofk5();
  139.                         prompt();
  140.                         break;
  141.                 case FK6:
  142.                         beep;
  143.                         break;
  144.                 case FK7:  /* select output channel */
  145.                         dokey7();
  146.                         prompt();
  147.                         break;
  148.                 case FK8:   /* set normal options */
  149.                         linespc = 0;  /* 6 lpi */
  150.                         putlinespc();
  151.                         length = 0x66;
  152.                         putlength();
  153.                         style = DRAFT;
  154.                         putstyle();
  155.                         pitch = PICA;
  156.                         putpitch();
  157.                         lqspc = NONE;
  158.                         putlqspc();
  159.                         printer = 0;
  160.                         putprinter();
  161.                         prompt();
  162.                         break;
  163.                 case FK9:  /* write the codes out and exit */
  164.                         dofk9();
  165.                         break;
  166.                 case FK10:
  167.                         exit2dos();
  168.                         domenu(TRUE);
  169.                         break;
  170.                 default:
  171.                         beep;
  172.                 }   /* end of switch */
  173.         }      /* end of main while */
  174. }         /* end of main() */
  175.  
  176.  
  177. domenu(int cmd)
  178. {
  179.         int i;
  180.  
  181.         /* if cmd is TRUE, then place current setting in menu for each item */
  182.         cls();
  183.         mkbox(0, 0, 80, 22, 0);   /* place the border on blank screen */
  184.         i = cntr(line1);
  185.         d_say(3, i, line1);
  186.         i = cntr(line2);
  187.         d_say(4, i, line2);
  188.         i = cntr(line3);
  189.         d_say(5, i, line3);
  190.         d_say(7, 15, line4);
  191.         if(cmd && (pitch != NONE))
  192.         putpitch();
  193.         d_say(8, 15, line5);
  194.         if(cmd && (style != NONE))
  195.         putstyle();
  196.         d_say(9, 15, line6);
  197.         if(cmd && (lqspc != NONE))
  198.         putlqspc();
  199.         d_say(10, 15, line7);
  200.         if(cmd && (length != NONE))
  201.         putlength();
  202.         d_say(11, 15, line8);
  203.         if(cmd && (linespc != NONE))
  204.         putlinespc();
  205.         d_say(12, 15, line9);
  206.         d_say(13, 15, line10);
  207.         putprinter();
  208.         d_say(14, 15, line11);
  209.         d_say(15, 15, line12);
  210.         d_say(16, 15, line13);
  211.         prompt();
  212. }
  213.  
  214. cntr(char *str)
  215. {       /* returns column to start printing */
  216.         int i;
  217.  
  218.         i = strlen(str);
  219.         --i;     /* account for newline character */
  220.         return(((80 - i) / 2) - 1);
  221. }
  222.  
  223. prompt(void)
  224. {
  225.         d_say(19, 15, cline);
  226.         d_say(19, 15, line14);
  227. }
  228.  
  229. warn(int value)
  230. {
  231.         beep;
  232.         switch(value)
  233.         {
  234.         case 1:
  235.                 d_say(19, 15, "Value too large.  Range is 0-11.");
  236.                 break;
  237.         case 2:
  238.                 d_say(19, 15, "Length value of 0 meaningless.");
  239.                 break;
  240.         default:
  241.                 prompt();
  242.                 return;
  243.         }
  244.         d_say(20, 15, "Strike any key to continue...");
  245.         getkey();
  246.         d_say(20, 15, cline);
  247.         prompt();
  248. }
  249.  
  250.  
  251. putpitch()
  252. {
  253.         if(pitch == PICA) { d_say(7, 27, pica); return; }
  254.         if(pitch == COND) { d_say(7, 27, cond); return; }
  255. }
  256.  
  257. putstyle()
  258. {
  259.         if(style == DRAFT) { d_say(8, 27, draft); return; }
  260.         if(style == LQ) { d_say(8, 27, lq); return; }
  261. }
  262.  
  263. putlqspc()
  264. {
  265.         char i;
  266.  
  267.         d_pos(9, 32, 0);
  268.         if(lqspc == NONE)
  269.         {
  270.                 fputs("  ", stdout);
  271.                 return;
  272.         }
  273.         i = (char)((lqspc >>4) | '0');
  274.         fputc(i, stdout);
  275.         i = (char)((lqspc & 0x0f) | '0');
  276.         fputc(i, stdout);
  277. }
  278.  
  279. putlength()
  280. {
  281.         char i;
  282.  
  283.         d_pos(10, 41, 0);
  284.         i = (char)((length >>4) | '0');
  285.         fputc(i, stdout);
  286.         i = (char)((length & 0x0f) | '0');
  287.         fputc(i, stdout);
  288. }
  289.  
  290. putlinespc()
  291. {
  292.         d_pos(11, 34, 0);
  293.         if(linespc == 0)
  294.                 puts("6 lpi");
  295.         else    puts("8 lpi");
  296. }
  297.  
  298. putprinter()
  299. {
  300.         d_pos(13, 37, 0);
  301.         switch(printer)
  302.         {
  303.         case 0:
  304.         default:
  305.                 puts(prn);
  306.                 return;
  307.         case 1:
  308.                 puts(lpt1);
  309.                 return;
  310.         case 2:
  311.                 puts(lpt2);
  312.                 return;
  313.         }
  314. }
  315.  
  316. dofk1()
  317. {
  318.         char chr;
  319.  
  320.         if(pitch == NONE)
  321.         {
  322.                 pitch = PICA;
  323.                 putpitch();
  324.         }
  325.         d_pos(7, 27, 0);
  326.         while((chr = getkey()) != '\r')
  327.         {
  328.                 if(chr > 255)
  329.                 {
  330.                         beep;
  331.                         continue;
  332.                 }
  333.                 if(chr != ' ')
  334.                 {
  335.                         beep;
  336.                         continue;
  337.                 }
  338.                 ++pitch;
  339.                 pitch &= 0x01;  /* toggle between 0 and 1 only */
  340.                 putpitch();
  341.                 d_pos(7, 27, 0);
  342.         }
  343. }
  344.  
  345. dofk2()
  346. {
  347.         char chr;
  348.  
  349.         if(style == NONE)
  350.         {
  351.                 style = DRAFT;
  352.                 putstyle();
  353.         }
  354.         d_pos(8, 27, 0);
  355.         while((chr = getkey()) != '\r')
  356.         {
  357.                 if(chr > 255)
  358.                 {
  359.                         beep;
  360.                         continue;
  361.                 }
  362.                 if(chr != ' ')
  363.                 {
  364.                         beep;
  365.                         continue;
  366.                 }
  367.                 ++style;
  368.                 style &= 0x01;  /* toggle between 0 and 1 only */
  369.                 putstyle();
  370.                 d_pos(8, 27, 0);
  371.         }
  372. }
  373.  
  374. dofk5()
  375. {
  376.         char chr;
  377.  
  378.         if(linespc == NONE)
  379.         {
  380.                 linespc = 0;
  381.                 putlinespc();
  382.         }
  383.         d_pos(11, 34, 0);
  384.         while((chr = getkey()) != '\r')
  385.         {
  386.                 if(chr > 255)
  387.                 {
  388.                         beep;
  389.                         continue;
  390.                 }
  391.                 if(chr != ' ')
  392.                 {
  393.                         beep;
  394.                         continue;
  395.                 }
  396.                 ++linespc;
  397.                 linespc &= 0x01;  /* toggle between 0 and 1 only */
  398.                 putlinespc();
  399.                 d_pos(11, 34, 0);
  400.         }
  401. }
  402.  
  403. dokey7()
  404. {
  405.         char chr;
  406.  
  407.         d_pos(13, 37, 0);
  408.         while((chr = getkey()) != '\r')
  409.         {
  410.                 if(chr > 255)
  411.                 {
  412.                         beep;
  413.                         continue;
  414.                 }
  415.                 if(chr != ' ')
  416.                 {
  417.                         beep;
  418.                         continue;
  419.                 }
  420.                 ++printer;
  421.                 if(printer > 2)
  422.             printer = 0;  /* trap wrap around */
  423.                 putprinter();
  424.                 d_pos(13, 37, 0);
  425.         }
  426. }
  427.  
  428. dofk9()
  429. {
  430.         short i, j;
  431.         short codes[32];
  432.         FILE *fd;
  433.  
  434.         i = 0;
  435.         fputs("  Sending codes...", stdout);
  436.         if(pitch == PICA)
  437.                 codes[i++] = 0x12;
  438.         if(pitch == COND)
  439.                 codes[i++] = 0x0f;
  440.         if(style != NONE)
  441.         {
  442.                 codes[i++] = ESC;
  443.                 codes[i++] = 0x58;
  444.                 switch(style)
  445.                 {
  446.                 default:
  447.                         i -= 2;
  448.                         break;
  449.                 case DRAFT:
  450.                         codes[i++] = 0;
  451.                         break;
  452.                 case LQ:
  453.                         codes[i++] = 1;
  454.                         break;
  455.                 }
  456.         }
  457.         if((style == LQ) && (lqspc != NONE))
  458.         {
  459.                 codes[i++] = ESC;
  460.                 codes[i++] = 0x56;
  461.                 codes[i++] = (((lqspc >> 4) * 10) + (lqspc & 0x0f));
  462.         }
  463.         if(length != NONE)
  464.         {
  465.                 codes[i++] = ESC;
  466.                 codes[i++] = 0x43;
  467.                 codes[i++] = (((length >> 4) * 10) + (length & 0x0f));
  468.         }
  469.         if(linespc == 0)
  470.         {
  471.                 codes[i++] = ESC;
  472.                 codes[i++] = 0x32;
  473.         }
  474.         if(linespc == 1)
  475.         {
  476.                 codes[i++] = ESC;
  477.                 codes[i++] = 0x30;
  478.         }
  479.         /* i has count of characters to place */
  480.  
  481.         if(printer == 1)
  482.                 fd = fopen("LPT1", "wb");
  483.         if(printer == 2)
  484.                 fd = fopen("LPT2", "wb");
  485.         else    fd = stdprn;
  486.  
  487.         if(fd == NULL)
  488.                 error("Cannot open printer channel");
  489.  
  490.         for(j = 0; j < i; ++j)
  491.                 fputc(codes[j], fd);
  492.         cls();
  493.         exit(0);
  494. }
  495.  
  496.  
  497. get2digs(row, col) int row, col;
  498. {
  499.         int i, j;
  500.         char chr;
  501.  
  502.         i = j = 0;
  503.         d_pos(row, col, 0);
  504.         puts("  ");
  505.         d_pos(row, col, 0);
  506.         while((chr = getkey()) != '\r')
  507.         {
  508.                 if(i > 2)
  509.                 {
  510.                         beep;
  511.                         continue;
  512.                 }
  513.                 if(chr > 255)
  514.                 {
  515.                         beep;
  516.                         continue;
  517.                 }
  518.                 if(chr == '\b')
  519.                 {
  520.                         j = i = 0;
  521.                         d_pos(row, col, 0);
  522.                         puts("  ");
  523.                         d_pos(row, col, 0);
  524.                         continue;
  525.                 }
  526.                 if(chr == ESC)
  527.                 {
  528.                         d_pos(row, col, 0);
  529.                         puts("  ");
  530.                         return(NONE);
  531.                 }
  532.                 if(!isdigit(chr))
  533.                 {
  534.                         beep;
  535.                         continue;
  536.                 }
  537.                 putchar(chr);  /* echo it to screen */
  538.                 j = j<<4;
  539.                 j |= (chr & 0x0f);
  540.                 ++i;
  541.         }
  542.         if(i == 0)
  543.                 return(NONE);
  544.         else    return(j);
  545. }
  546.